package network;

import junit.framework.TestCase;
import junit.framework.Assert;

import java.io.IOException;
import java.net.*;
import java.util.HashSet;
import java.util.Scanner;


public class TeamCuratorTest extends TestCase {
	
	TeamCurator tc;
	
	public void testTeamCurator(){
		TeamCurator.exploitFileName="perl src\\exploit_template.pl";
		tc=new TeamCurator("10.1.0.", "KEVA");
		Assert.assertEquals("KEVA", tc.teamName);
		Assert.assertEquals("10.1.0.3", tc.teamIp);
	}
	

	public void testRun(){
		TeamCurator.efServerIp="127.0.0.1";
		TeamCurator.efServerPort=62674;
		try {
			ServerSocket server=new ServerSocket(62674);
			tc=new TeamCurator("10.1.0.", "KEVA");
			tc.start();
			Socket client=server.accept();
			Scanner s=new Scanner(client.getInputStream());
			HashSet<String> received=new HashSet<String>();
			for(int i=0; i<50; ++i){
				received.add(s.nextLine());
			}
			for(String str:tc.sent){
				if(!received.contains(str)){
					Assert.fail();
				}
			}
			tc.interrupt();
			client.close();
			server.close();
		} catch (IOException e) {
			return;
		}
		
	}

	
}
